import * as api from '../../api/getdata.js'
import request from '../../utils/request.js'
// import list from './Admin.json'
export default {
    namespaced:true,
    state: {
        ishow: false,
        judge: "",//判断添加修改
        listIndex: "",
        // xgishow:false,
        glyName: '',//管理员名字
        glyUser: '',//管理员账号
        glyrole: '',//所属角色
        newdate: '',//创建时间
        tjName: '',//添加名称
        tjPhone: '',//添加手机号
        tjuser: "",
        tjPass: '',//添加密码
        tjTissue: '',//添加组织
        tjRole: '',//添加角色
        tjTime: '',
        list:[],
        // data:[]
    },
    getters: {
        getTime(state) {
            let yy = new Date().getFullYear();
            let mm = new Date().getMonth() + 1;
            let dd = new Date().getDate();
            state.tjTime = yy + '-' + mm + '-' + dd
        },
        getSeek(state) {
            return state.list.filter(
                item => item.name.indexOf(state.glyName) !== -1 &&
                    item.user.indexOf(state.glyUser) !== -1 &&
                    item.role.indexOf(state.glyrole) !== -1 &&
                    item.time.indexOf(state.newdate) !== -1
            )
        }
    },
    mutations: {
        setList(state ,ages){
            state.data = ages
        },
        ishowAll(state, val) {
            state.ishow = !state.ishow
            state.judge = val
            if (val === 2) {
                console.log(state.list[state.listIndex].name);
                state.tjName = state.list[state.listIndex].name
                state.tjPhone = state.list[state.listIndex].phone
                state.tjuser = state.list[state.listIndex].user
                state.tjTissue = state.list[state.listIndex].tissue
                state.tjRole = state.list[state.listIndex].role
                state.tjPass = state.list[state.listIndex].pass
            }
 

        },
        xgIshow(state) {
            state.xgishow = !state.xgishow
        },
        getBtn(state) {
            if (state.judge === 1) {
                state.list.push({
                    id: state.list.length + 2,
                    name: state.tjName,
                    user: state.tjuser,
                    phone: state.tjPhone,
                    tissue: state.tjTissue,
                    role: state.tjRole,
                    time: state.tjTime,
                    pass: state.tjPass
                })
            }
            if (state.judge === 2) { 
                state.list[state.listIndex].name = state.tjName
                state.list[state.listIndex].phone = state.tjPhone
                state.list[state.listIndex].user = state.tjuser
                state.list[state.listIndex].tissue = state.tjTissue
                state.list[state.listIndex].role = state.tjRole
                state.list[state.listIndex].pass = state.tjPass
                // state.list[state.listIndex].time = state.tjTime
            }

        },
    },
    actions: {
        async getData(context) {
            let res = await api.getdata().then((res) => {return res})
            console.log(res);
            context.state.list = res.data
            console.log(context.state.data = res);
        }
    }
}